﻿using SKBKontur.Cassandra.Proxy.Management;
using log4net.Appender;
using log4net.Core;
using SKBKontur.Cassandra.Logging.Model;
using SKBKontur.Cassandra.Logging.Storage;
using SKBKontur.Cassandra.Proxy;
using SKBKontur.Logging;

namespace CassandraStressTest
{
    public class Appender : IAppender
    {
        private static readonly ILogEventWriter LogEventWriter;
        public static SimpleCassandraLoggingConfigurator Configurator;

        public bool IncludeLocationInfo { get; set; }

        static Appender()
        {
            var Conf = new ConfigurationInfo("LogNight", "Master", "Exception", "Info", "Warn", "Debug", "Error", "Fatal",
                                             0, 0, 0, 0, 0, 0);
            Configurator = new SimpleCassandraLoggingConfigurator(Conf, new ConsoleLevelDispatchingLogEventWriterConfigurator("\r\n"),
                                          new ProxyFactory("node1", 9160),
                                          new ProxyFactory("node2", 9160),
                                          new ProxyFactory("node3", 9160));
            LogEventWriter = new LevelDispatchingLogEventWriter(Configurator);
        }

        #region IAppender Members

        public string Name { get; set; }

        public void Close()
        {
        }

        public void DoAppend(LoggingEvent loggingEvent)
        {
            LogEventWriter.Create(new log4netEvent(loggingEvent, Name, IncludeLocationInfo));
        }

        #endregion
    }
}